/*********服务器文件server.js**********/
//引入必须的express模块文件
const express = require('express')
const cors = require('cors')
//创建WEB服务器
const app = express()
//定义指定的端口，并监听此端口
const port = 8080
app.listen(port, () => {
	console.log('已成功监听端口:' + port)
})
//添加中间件
app.use(express.urlencoded({
	extended: false
}))
//解决跨越中间件
app.use(cors())
//添加错误处理中间件，拦截路由中传递过来的错误
app.use((err, req, res, next) => {
	//err 传递过来的错误
	console.log(err);
	//响应服务器端错误
	res.send({
		code: 500,
		msg: '服务器端错误'
	});
});
//引入自定义的用户路由器模块
const navRouter = require('./router/nav.js')
const onlinemessageRouer = require('./router/onlinemessage.js')
const slidshowRouter = require('./router/slideshow.js')
const bannerRouter = require('./router/banner.js')
const detailRouter = require('./router/detail.js')

//使用路由器(前缀,路由器名字)
app.use('/v1/index.php', navRouter)
app.use('/v1/index.php', onlinemessageRouer)
app.use('/v1/index.php', slidshowRouter)
app.use('/v1/index.php', bannerRouter)
app.use('/v1/index.php', detailRouter)
